/*
 * Copyright (C) 2017-2019 Alibaba Group Holding Limited
 */

/******************************************************************************
 * @file     pin.h
 * @brief    header File for pin definition
 * @version  V1.5
 * @date     24. May 2019
 ******************************************************************************/
#ifndef _PIN_H_
#define _PIN_H_

#include <stdint.h>
#include "pinmux.h"
#include "pin_name.h"

#ifdef __cplusplus
extern "C" {
#endif

#define CLOCK_GETTIME_USE_TIMER_ID      0
#define EXAMPLE_DEST_MAILBOX_IDX        1

#define WAKEUP_PIN                      PA0
#define WAKEUP_PIN_FUNC                 PIN_FUNC_GPIO
#define EXAMPLE_BOARD_WAKEUP_PIN_NAME   "PA15"
#define EXAMPLE_WAKEUP_NUM              WAKEUPN_GPIOC0
#define CK804_PRINT                     2

#if 0
#define CONSOLE_TXD                     PB2
#define CONSOLE_RXD                     PB0
#define CONSOLE_TXD_FUNC                PB2_USI0_SD0
#define CONSOLE_RXD_FUNC                PB0_USI0_SCLK
#define CONSOLE_IDX                     0
#endif

#define EXAMPLE_USART_IDX               0
#define EXAMPLE_PIN_USART_TX            PB2
#define EXAMPLE_PIN_USART_RX            PB0
#define EXAMPLE_PIN_USART_TX_FUNC       PB2_USI0_SD0
#define EXAMPLE_PIN_USART_RX_FUNC       PB0_USI0_SCLK

#define EXAMPLE_SPI_IDX                 2
#define EXAMPLE_PIN_SPI_MOSI            PB10
#define EXAMPLE_PIN_SPI_MISO            PB11
#define EXAMPLE_PIN_SPI_CS              PB9
#define EXAMPLE_PIN_SPI_SCK             PB8
#define EXAMPLE_PIN_SPI_MOSI_FUNC       PB10_USI2_SD0
#define EXAMPLE_PIN_SPI_MISO_FUNC       PB11_USI2_SD1
#define EXAMPLE_PIN_SPI_CS_FUNC         PIN_FUNC_GPIO
#define EXAMPLE_PIN_SPI_SCK_FUNC        PB8_USI2_SCLK

#define EXAMPLE_IIC_IDX                 3
#define EXAMPLE_PIN_IIC_SDA             PB14
#define EXAMPLE_PIN_IIC_SCL             PB12
#define EXAMPLE_PIN_IIC_SDA_FUNC        PB14_USI3_SD0
#define EXAMPLE_PIN_IIC_SCL_FUNC        PB12_USI3_SCLK

#define EXAMPLE_GPIO_PIN                PB22
#define EXAMPLE_BOARD_GPIO_PIN_NAME     "PB22"
#define EXAMPLE_GPIO_PIN_FUNC           PIN_FUNC_GPIO

#define EXAMPLE_PWM_IDX                 0
#define EXAMPLE_PWM_CH_IDX              0
#define EXAMPLE_PWM_CH                  PC20
#define EXAMPLE_PWM_CH_FUNC             PC20_PWM_CH0

#define EXAMPLE_QSPI_IDX                0
#define EXAMPLE_PIN_QSPI_MOSI           PA12
#define EXAMPLE_PIN_QSPI_MISO           PA13
#define EXAMPLE_PIN_QSPI_CS             PA11
#define EXAMPLE_PIN_QSPI_SCK            PA10
#define EXAMPLE_PIN_QSPI_HOLD           PA15
#define EXAMPLE_PIN_QSPI_WP             PA14
#define EXAMPLE_PIN_QSPI_MOSI_FUNC      PA12_QSPI_D0_MOSI
#define EXAMPLE_PIN_QSPI_MISO_FUNC      PA13_QSPI_D1_MISO
#define EXAMPLE_PIN_QSPI_CS_FUNC        PA11_QSPI_CSN
#define EXAMPLE_PIN_QSPI_SCK_FUNC       PA10_QSPI_SCLK
#define EXAMPLE_PIN_QSPI_WP_FUNC        PA14_QSPI_D2_WP
#define EXAMPLE_PIN_QSPI_HOLD_FUNC      PA15_QSPI_D3_HOLD

#define EXAMPLE_I2S_IDX                 0
#define EXAMPLE_I2S_MCLK                PA16
#define EXAMPLE_I2S_SCLK                PA17
#define EXAMPLE_I2S_WSCLK               PA18
#define EXAMPLE_I2S_SDA                 PA19
#define EXAMPLE_I2S_MCLK_FUNC           PA16_I2S0_MCLK
#define EXAMPLE_I2S_SCLK_FUNC           PA17_I2S0_SCK
#define EXAMPLE_I2S_WSCLK_FUNC          PA18_I2S0_WS
#define EXAMPLE_I2S_SDA_FUNC            PA19_I2S0_SD

#define EXAMPLE_CAMERA_IIC_IDX          10
#define EXAMPLE_ADC_CHANNEL_USR_DEF0    0
#define EXAMPLE_ADC_CHANNEL_DEF1        1
#define EXAMPLE_ADC_CHANNEL_DEF2        2

#define EXAMPLE_CAMERA0_IIC_IDX          10
#define EXAMPLE_PIN_CAMERA0_IIC_SDA      PC2
#define EXAMPLE_PIN_CAMERA0_IIC_SCL      PC0
#define EXAMPLE_PIN_CAMERA0_IIC_SDA_FUNC PC2_USI10_SD0
#define EXAMPLE_PIN_CAMERA0_IIC_SCL_FUNC PC0_USI10_SCLK


#define EXAMPLE_CAMERA1_IIC_IDX          11
#define EXAMPLE_PIN_CAMERA1_IIC_SDA      PC6
#define EXAMPLE_PIN_CAMERA1_IIC_SCL      PC4
#define EXAMPLE_PIN_CAMERA1_IIC_SDA_FUNC PC6_USI11_SD0
#define EXAMPLE_PIN_CAMERA1_IIC_SCL_FUNC PC4_USI11_SCLK

// Camera2 use same IIC with Camera0, but slave address difference
#define EXAMPLE_CAMERA2_IIC_IDX          EXAMPLE_CAMERA0_IIC_IDX
#define EXAMPLE_PIN_CAMERA2_IIC_SDA      EXAMPLE_PIN_CAMERA0_IIC_SDA
#define EXAMPLE_PIN_CAMERA2_IIC_SCL      EXAMPLE_PIN_CAMERA0_IIC_SCL
#define EXAMPLE_PIN_CAMERA2_IIC_SDA_FUNC EXAMPLE_PIN_CAMERA0_IIC_SDA_FUNC
#define EXAMPLE_PIN_CAMERA2_IIC_SCL_FUNC EXAMPLE_PIN_CAMERA0_IIC_SCL_FUNC

#define EXAMPLE_MIPI_CSI_IDX            0
#define EXAMPLE_CAMERA_IDX              0
#define EXAMPLE_MIPI_CSI_READER_IDX     0

#define EXAMPLE_ADC_CHANNEL_USR_DEF0    0
#define EXAMPLE_ADC_CHANNEL_DEF1        1
#define EXAMPLE_ADC_CHANNEL_DEF2        2

#define EXAMPLE_SDIO_IDX                0

/* tests pin manager */
#define TEST_USART_IDX                  2
#define TEST_PIN_USART_TX               PB10
#define TEST_PIN_USART_RX               PB8
#define TEST_PIN_USART_TX_FUNC          PB10_USI2_SD0
#define TEST_PIN_USART_RX_FUNC          PB8_USI2_SCLK

#define TEST_SPI_IDX                    1
#define TEST_PIN_SPI_MISO               PB6
#define TEST_PIN_SPI_MOSI               PB7
#define TEST_PIN_SPI_CS                 PB5
#define TEST_PIN_SPI_SCK                PB4
#define TEST_PIN_SPI_MISO_FUNC          PB6_USI1_SD0
#define TEST_PIN_SPI_MOSI_FUNC          PB7_USI1_SD1
#define TEST_PIN_SPI_CS_FUNC            PIN_FUNC_GPIO
#define TEST_PIN_SPI_SCK_FUNC           PB4_USI1_SCLK

#define TEST_IIC_IDX                    3
#define TEST_PIN_IIC_SDA                PB14
#define TEST_PIN_IIC_SCL                PB12
#define TEST_PIN_IIC_SDA_FUNC           PB14_USI3_SD0
#define TEST_PIN_IIC_SCL_FUNC           PB12_USI3_SCLK

#define TEST_GPIO_PIN                   PC20
#define TEST_BOARD_GPIO_PIN_NAME        "PWM_CH0"
#define TEST_GPIO_PIN_FUNC              PIN_FUNC_GPIO

#define TEST_PWM_IDX                    0
#define TEST_PWM_CH                     0
#define TEST_PWM_CH0                    PC20
#define TEST_PWM_CH0_FUNC               PC20_PWM_CH0
#define TEST_PWM_CH1                    PC21
#define TEST_PWM_CH1_FUNC               PC21_PWM_CH2
#define TEST_PWM_CH2                    PC22
#define TEST_PWM_CH2_FUNC               PC22_PWM_CH4
#define TEST_PWM_CH3                    PC23
#define TEST_PWM_CH3_FUNC               PC23_PWM_CH6
#define TEST_PWM_CH4                    PC24
#define TEST_PWM_CH4_FUNC               PC24_PWM_CH8
#define TEST_PWM_CH5                    PC25
#define TEST_PWM_CH5_FUNC               PC25_PWM_CH10

#define TEST_PIN_QSPI_MOSI              PA12
#define TEST_PIN_QSPI_MISO              PA13
#define TEST_PIN_QSPI_CS                PA11
#define TEST_PIN_QSPI_SCK               PA10
#define TEST_PIN_QSPI_HOLD              PA15
#define TEST_PIN_QSPI_WP                PA14
#define TEST_PIN_QSPI_MOSI_FUNC         PA12_QSPI_D0_MOSI
#define TEST_PIN_QSPI_MISO_FUNC         PA13_QSPI_D1_MISO
#define TEST_PIN_QSPI_CS_FUNC           PA11_QSPI_CSN
#define TEST_PIN_QSPI_SCK_FUNC          PA10_QSPI_SCLK
#define TEST_PIN_QSPI_WP_FUNC           PA14_QSPI_D2_WP
#define TEST_PIN_QSPI_HOLD_FUNC         PA15_QSPI_D3_HOLD

#define TEST_I2S_IDX                    0
#define TEST_I2S_SLAVE_IDX              1
#define TEST_I2S_MCLK                   PA16
#define TEST_I2S_SCLK                   PA17
#define TEST_I2S_WSCLK                  PA18
#define TEST_I2S_SDA                    PA19
#define TEST_I2S_MCLK_FUNC              PA16_I2S0_MCLK
#define TEST_I2S_SCLK_FUNC              PA17_I2S0_SCK
#define TEST_I2S_WSCLK_FUNC             PA18_I2S0_WS
#define TEST_I2S_SDA_FUNC               PA19_I2S0_SD

#define TEST_I2S_SLAVE_MCLK             PA20
#define TEST_I2S_SLAVE_SCLK             PA21
#define TEST_I2S_SLAVE_WSCLK            PA22
#define TEST_I2S_SLAVE_SDA              PA23
#define TEST_I2S_SLAVE_MCLK_FUNC        PA20_I2S1_MCLK
#define TEST_I2S_SLAVE_SCLK_FUNC        PA21_I2S1_SCK
#define TEST_I2S_SLAVE_WSCLK_FUNC       PA22_I2S1_WS
#define TEST_I2S_SLAVE_SDA_FUNC         PA23_I2S1_SD

#define TEST_MIPI_DSI_HOST_IDX          0

#define MUSIC_SIZE_BUFFER               (500 * 1024)
#define WAV_SPACE_SIZE                  (500 * 1024)

#define COMM_USART_IDX                  2
#define COMM_USART_MODE                 UART_HARD_USI

#ifdef __cplusplus
}
#endif

#endif /* _PIN_H_ */

